from django.test import TestCase

# Create your tests here.


import openai

ApiKey = "sk-Fkphr3IyUwcJQcVx68CeA5B82fA14aEdA034A91323250d01"


class api_keys:
    api_key = ApiKey
    proxy = "http://127.0.0.1:7890"
    api_base = "https://api.wzunjh.top/v1"


response = openai.ChatCompletion.create(
    api_key=api_keys.api_key,
    api_base=api_keys.api_base,
    model='gpt-3.5-turbo',
    messages=[{"role": "user", "content": "你好"}],
    temperature=0.7,
    stream=True
)

reply = ""

for line in response:
    if line["finish_reason"] is not None:
        data = ''
    else:
        data = line["choices"][0]["delta"].get("content", "")
        reply += data

print(reply)


#
# List = []
# for item in openai.Model.list()['data']:
#     if item["permission"][0]["allow_create_engine"]:
#         List.append(item['id'])
#
# print(List)


# my_list = [{'chatID': '262b25672f740444ce192cb59b366b7a', 'title': '你好'}, {'chatID': '41b49a63ccf1f2b38298514be41d7ea6', 'title': '你好'}, {'chatID': '52fc90e71d31c6bf7a4688d15583d79a', 'title': '树上有10只鸟，开枪打死了一只，请问树上还剩多少只'}, {'chatID': 'a3db991321c51c0971071203104eb656', 'title': '你是谁？'}]
# id_to_find = '52fc90e71d31c6bf7a4688d15583d79a'
# my_dict = next((d for d in my_list if d['chatID'] == id_to_find), None)
# print(my_dict)
# if my_dict:
#     my_dict['title'] = 'John'
# print(my_list)
